package com.dabai.qrtools.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.dabai.qrtools.R;
import com.dabai.qrtools.utils.DabaiUtils;
import com.dabai.qrtools.utils.ThemeUtils;
import com.google.android.material.appbar.MaterialToolbar;

import java.util.Objects;

public class FreeCopyActivity extends AppCompatActivity {

    private Context context;
    private MaterialToolbar mToolbar;
    private TextView mResulttext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_free_copy);
        initViews();

        context = this;

        ThemeUtils.setAutoUiModeStatusBar(this, this);
        setSupportActionBar(mToolbar);
        Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);

        Intent intent = getIntent();

        if (intent == null) {
            DabaiUtils.showToast(context,"结果为空，无法显示");
            finish();
            return;
        }

        String result = intent.getStringExtra("content");

        if (result == null) {
            DabaiUtils.showToast(context,"结果为空，无法显示");
            finish();
            return;
        }

        mResulttext.setText(result);
        getSupportActionBar().setTitle("自由复制("+result.length()+")");

    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId = item.getItemId();
        if (itemId == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void initViews() {
        mToolbar = findViewById(R.id.toolBar);
        mResulttext = findViewById(R.id.resultText);
    }
}